package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.FileUploadLog;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by wangjian7 on 2016/10/25.
 */
public class FileUploadLogConvert {
    public static DBObject castFileUploadLogToDBObject(FileUploadLog fileUploadLog) {
        DBObject dbo = new BasicDBObject();
        if (fileUploadLog.getId() != null) {
            dbo.put("_id", fileUploadLog.getId());
        }
        dbo.put("md5", fileUploadLog.getMd5());
        dbo.put("uploadStatus", fileUploadLog.getUploadStatus());
        dbo.put("fileUrl", fileUploadLog.getFileUrl());
        if(null!=fileUploadLog.getCreateTime()){
            dbo.put("createTime", fileUploadLog.getCreateTime());
        }
        if(null!=fileUploadLog.getUpdateTime()){
            dbo.put("updateTime", fileUploadLog.getUpdateTime());
        }
        return dbo;
    }
    public static FileUploadLog castDBObjectToFileUploadLog(DBObject dbObject){
        if(dbObject!=null){
            FileUploadLog fileUploadLog=new FileUploadLog();
            fileUploadLog.setId(ObjectUtils.toLong(dbObject.get("_id")));
            fileUploadLog.setMd5(ObjectUtils.toString(dbObject.get("md5")));
            fileUploadLog.setUploadStatus(ObjectUtils.toInteger(dbObject.get("uploadStatus")));
            fileUploadLog.setFileUrl(ObjectUtils.toString(dbObject.get("fileUrl")));
            if(dbObject.get("createTime")!=null){
                fileUploadLog.setCreateTime(ObjectUtils.toLong(dbObject.get("createTime")));
            }
            if(dbObject.get("updateTime")!=null){
                fileUploadLog.setUpdateTime(ObjectUtils.toLong(dbObject.get("updateTime")));
            }
            return fileUploadLog;
        }else{
            return null;
        }
    }
}
